import Vue from 'vue'
import Router from 'vue-router'

// 按需加载
const Login = resolve => require(['@/pages/Login'], resolve) // 登录页面
const Home = resolve => require(['@/pages/Home'], resolve) // 首页
const MainPage = resolve => require(['@/pages/MainPage'], resolve) // 主题页面
const AccountSecurity = resolve => require(['@/pages/AccountSecurity'], resolve) // 账号与资料页面
const ConsolePage = resolve => require(['@/pages/ConsolePage'], resolve) // 控制台页面
const LeaguePage = resolve => require(['@/pages/LeaguePage'], resolve) // 联赛列表页面
const MatchPage = resolve => require(['@/pages/MatchPage'], resolve) // 比赛列表页面
const PersonalData = resolve => require(['@/pages/PersonalData'], resolve) // 个人资料页面
const AccountSecurityPage = resolve => require(['@/pages/AccountSecurityPage'], resolve) // 账号安全页面
const UnbindPhone = resolve => require(['@/pages/UnbindPhone'], resolve) // 解绑手机号码
const BindEmail = resolve => require(['@/pages/BindEmail'], resolve) // 绑定邮箱页面
const ChangePassword = resolve => require(['@/pages/ChangePassword'], resolve) // 修改密码页面
const ForgetPassword = resolve => require(['@/pages/ForgetPassword'], resolve) // 忘记密码页面
const MatchInfos = resolve => require(['@/pages/MatchInfos'], resolve) // 比赛信息页面
const PlayerInfo = resolve => require(['@/pages/PlayerInfo'], resolve) // 球员信息页面
const MatchSchedule5V5 = resolve => require(['@/pages/5V5MatchSchedule'], resolve) // 5V5比赛信息页面
const MatchSchedule3V3 = resolve => require(['@/pages/3V3MatchSchedule'], resolve) // 3V3比赛信息页面

Vue.use(Router)

export default new Router({
  routes: [{
      path: '/Login',
      name: 'Login',
      component: Login,
      meta: {
        // auth: false // 是否需要判断是否登录
      }
    },
    {
      path: '/Home',
      name: 'Home',
      component: Home,
      meta: {
        // auth: true // 是否需要判断是否登录
      }
    },
    {
      path: '/',
      name: 'MainPage',
      component: MainPage,
      redirect: 'ConsolePage',
      meta: {
        // auth: true // 是否需要判断是否登录
      },
      children: [{
          path: '/ConsolePage',
          name: 'ConsolePage',
          // component: ConsolePage,
          component: LeaguePage,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        },
        {
          path: '/LeaguePage',
          name: 'LeaguePage',
          component: LeaguePage,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        },
        {
          path: '/MatchPage',
          name: 'MatchPage',
          component: MatchPage,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        }
      ]
    },
    {
      path: '/AccountSecurity',
      name: 'AccountSecurity',
      component: AccountSecurity,
      redirect: 'PersonalData',
      meta: {
        // auth: true // 是否需要判断是否登录
      },
      children: [{
          path: '/PersonalData',
          name: 'PersonalData',
          component: PersonalData,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        },
        {
          path: '/AccountSecurityPage',
          name: 'AccountSecurityPage',
          component: AccountSecurityPage,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        },
        {
          path: '/UnbindPhone',
          name: 'UnbindPhone',
          component: UnbindPhone,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        },
        {
          path: '/BindEmail',
          name: 'BindEmail',
          component: BindEmail,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        },
        {
          path: '/ChangePassword',
          name: 'ChangePassword',
          component: ChangePassword,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        },
        {
          path: '/ForgetPassword',
          name: 'ForgetPassword',
          component: ForgetPassword,
          meta: {
            // auth: true // 是否需要判断是否登录
          }
        }
      ]
    },
    {
      path: '/MatchInfos',
      name: 'MatchInfos',
      component: MatchInfos,
      meta: {
        // auth: true // 是否需要判断是否登录
      }
    },
    {
      path: '/PlayerInfo',
      name: 'PlayerInfo',
      component: PlayerInfo,
      meta: {
        // auth: true // 是否需要判断是否登录
      }
    },
    {
      path: '/MatchSchedule5V5',
      name: 'MatchSchedule5V5',
      component: MatchSchedule5V5,
      meta: {
        // auth: true // 是否需要判断是否登录
      }
    },
    {
      path: '/MatchSchedule3V3',
      name: 'MatchSchedule3V3',
      component: MatchSchedule3V3,
      meta: {
        // auth: true // 是否需要判断是否登录
      }
    }
  ]
})

const VueRouterPush = Router.prototype.push
Router.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
